第 19 期 Python 程式設計入門-作業任務4


  1. 問答申論題
    Python 字串物件的方法 str.title()
    官方描述介紹:

    Return a titlecased version of the binary sequence where words start with an uppercase ASCII character and the remaining characters are lowercase. Uncased byte values are left unmodified.

意思即為透過str.title()這個物件方法,將字串單字首字元以大寫回傳,其餘字元為小寫。

使用範例:

text = 'hello world, how are you today?'
print(text.title())
#得到'Hello World, How Are You Today?'

2.程式設計實作題
設計一個程式:讓使用者可以輸入英文字串,並透過取出使用者輸入的字串將最後一個字元取出轉成英文大寫後印出結果。

user_text = input('請輸入英文字串: ')
if user_text.isalpha():
  print(user_text[-1].upper())
else:
  print('請輸入英文字串')

(此方法無法判斷使用者輸入中文內容)







你可能感興趣的文章

3. 線性串列

3. 線性串列

Jest 自己的程式自己測試

Jest 自己的程式自己測試

Vue3 Proxy ? Vue2 Define Property 的不同?

Vue3 Proxy ? Vue2 Define Property 的不同?






留言討論